/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ViewAthletDetails.java
 *
 * Created on 07.06.2009, 17:49:12
 */

package trackreggui;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;
import webreg.model.Disciplin;
import webreg.model.exceptions.EmptyDescriptionException;
import webreg.model.exceptions.EmptyLabelException;

/**
 *
 * @author STKNOLL
 */
public class ViewDisciplinDetails extends javax.swing.JDialog {

    /** Creates new form ViewAthletDetails */
    public ViewDisciplinDetails(java.awt.Frame parent) {
        super(parent);
        initComponents();
        mUseDisciplin = null;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        disciplinCaptionLabel = new javax.swing.JLabel();
        disciplinCaptionSeparator = new javax.swing.JSeparator();
        priceTextField = new javax.swing.JTextField();
        descriptionTextField = new javax.swing.JTextField();
        labelTextField = new javax.swing.JTextField();
        descriptionLabel = new javax.swing.JLabel();
        priceLabel = new javax.swing.JLabel();
        labelLabel = new javax.swing.JLabel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getResourceMap(ViewDisciplinDetails.class);
        setTitle(resourceMap.getString("disziplinDetailsForm.title")); // NOI18N
        setMinimumSize(new java.awt.Dimension(200, 200));
        setModal(true);
        setName("disziplinDetailsForm"); // NOI18N
        setResizable(false);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        disciplinCaptionLabel.setFont(resourceMap.getFont("disciplinCaptionLabel.font")); // NOI18N
        disciplinCaptionLabel.setText(resourceMap.getString("disciplinCaptionLabel.text")); // NOI18N
        disciplinCaptionLabel.setName("disciplinCaptionLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 5, 10);
        getContentPane().add(disciplinCaptionLabel, gridBagConstraints);

        disciplinCaptionSeparator.setName("disciplinCaptionSeparator"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 5, 10);
        getContentPane().add(disciplinCaptionSeparator, gridBagConstraints);

        priceTextField.setText(resourceMap.getString("priceTextField.text")); // NOI18N
        priceTextField.setName("priceTextField"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.8;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(priceTextField, gridBagConstraints);

        descriptionTextField.setText(resourceMap.getString("descriptionTextField.text")); // NOI18N
        descriptionTextField.setName("descriptionTextField"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.8;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(descriptionTextField, gridBagConstraints);

        labelTextField.setText(resourceMap.getString("labelTextField.text")); // NOI18N
        labelTextField.setName("labelTextField"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.8;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(labelTextField, gridBagConstraints);

        descriptionLabel.setText(resourceMap.getString("descriptionLabel.text")); // NOI18N
        descriptionLabel.setName("descriptionLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(descriptionLabel, gridBagConstraints);

        priceLabel.setText(resourceMap.getString("priceLabel.text")); // NOI18N
        priceLabel.setName("priceLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(priceLabel, gridBagConstraints);

        labelLabel.setText(resourceMap.getString("labelLabel.text")); // NOI18N
        labelLabel.setName("labelLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(labelLabel, gridBagConstraints);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getActionMap(ViewDisciplinDetails.class, this);
        okButton.setAction(actionMap.get("createDisciplin")); // NOI18N
        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setToolTipText(resourceMap.getString("okButton.toolTipText")); // NOI18N
        okButton.setMaximumSize(new java.awt.Dimension(87, 23));
        okButton.setMinimumSize(new java.awt.Dimension(87, 23));
        okButton.setName("okButton"); // NOI18N
        okButton.setPreferredSize(new java.awt.Dimension(87, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(okButton, gridBagConstraints);

        cancelButton.setAction(actionMap.get("closeDisciplinDetails")); // NOI18N
        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setToolTipText(resourceMap.getString("cancelButton.toolTipText")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.weighty = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(cancelButton, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void createDisciplin() {
        try {
            mUseDisciplin = new Disciplin();
            mUseDisciplin.setLabel(labelTextField.getText());
            mUseDisciplin.setDescription(descriptionTextField.getText());
            mUseDisciplin.setPrice(priceTextField.getText());
            closeDisciplinDetails();
        } catch (EmptyDescriptionException ex) {
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getResourceMap(ViewDisciplinDetails.class);
            JOptionPane.showMessageDialog(null, resourceMap.getString("errorEmptyDescription.text"), resourceMap.getString("errorEmptyDescription.title"), JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(ViewDisciplinDetails.class.getName()).log(Level.SEVERE, null, ex);
        } catch (EmptyLabelException ex) {
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getResourceMap(ViewDisciplinDetails.class);
            JOptionPane.showMessageDialog(null, resourceMap.getString("errorEmptyLabel.text"), resourceMap.getString("errorEmptyLabel.title"), JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(ViewDisciplinDetails.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Action
    public void closeDisciplinDetails() {
        setVisible(false);
    }

    public void setDisciplin(Disciplin inDisciplin) {
        labelTextField.setText( inDisciplin.getLabel() );
        descriptionTextField.setText( inDisciplin.getDescription());
        priceTextField.setText( inDisciplin.getPriceAsString() );
    }

    public Disciplin getDisciplin() {
        return mUseDisciplin;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JTextField descriptionTextField;
    private javax.swing.JLabel disciplinCaptionLabel;
    private javax.swing.JSeparator disciplinCaptionSeparator;
    private javax.swing.JLabel labelLabel;
    private javax.swing.JTextField labelTextField;
    private javax.swing.JButton okButton;
    private javax.swing.JLabel priceLabel;
    private javax.swing.JTextField priceTextField;
    // End of variables declaration//GEN-END:variables

    private Disciplin mUseDisciplin;

}
